<%@page import="org.prs.model.RelationshipType"%>
<%@page import="org.prs.persistence.RelationshipTypeDatabasePersitence"%>
<%@page import="java.util.List"%>
<%@page import="org.prs.persistence.SchoolStageDatabasePersistence"%>
<%@page import="org.prs.model.SchoolStage"%>
<%@page import="org.prs.model.User"%>
<%@page import="org.apache.commons.validator.GenericValidator"%>
<%@page contentType="text/html"  language="java" %>
<%
            String childCreationMessage = (String) session.getAttribute("childcreationmsg");
            session.setAttribute("childcreationmsg", null);
            User loggedInUser = (User) session.getAttribute("loggedinuser");

            if (loggedInUser == null) {
                session.setAttribute("loginmsg", "<div id='loginmsg'>Please log in to use services</div>");
                response.sendRedirect("index.jsp");
            }
            SchoolStageDatabasePersistence persistSchoolStage = new SchoolStageDatabasePersistence();
            List<SchoolStage> schoolStages = persistSchoolStage.getAllSchoolStages();
            RelationshipTypeDatabasePersitence persistRelationshipType = new RelationshipTypeDatabasePersitence();
            List<RelationshipType> relationshipTypes = persistRelationshipType.getAllRelationshipTypes();
%>
%>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>Patnership Record System</title>
        <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
        <script type="text/javascript" src="js/menu.js">
        </script>

        <title>Patnership Registration System | New Child</title>
        <link rel="SHORTCUT ICON" href="images/favicon.ico" />
        <link rel="stylesheet" type="text/css" href="css/menu/menu.css"/>
        <script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
        <script type="text/javascript" src="js/jquery-ui-1.8.10.custom.min.js"></script>
        <link rel="stylesheet" href="css/jquery/jquery-ui-1.8.10.custom.css" type="text/css" />
        <script type="text/javascript">
            $(function() {
                $( ".datefield" ).datepicker({
                    changeMonth: true,
                    changeYear: true,
                    dateFormat: 'dd/mm/yy'
                });                
            });
        </script>
    </head>
    <body>
        <div id="wrapper">
            <div id="header">
                <div id="logo">
                    <h1><a href="#">Patnership Record System </a></h1>
                </div>
                <div id="menu">
                    <jsp:include page="includes/header.jsp"></jsp:include>
                </div>
            </div>
            <!-- end #header -->
            <div id="page">
                <div id="page-bgtop">
                    <div id="page-bgbtm">
                        <div id="content">
                            <form class='foorm' name='newChildForm' id='newChildForm' method='post' action='newchild'>
                                <%
                                            if (!GenericValidator.isBlankOrNull(childCreationMessage)) {
                                                out.println(childCreationMessage);
                                            }
                                %>
                                The fields marked with <font color='#ff0000'>*</font> are mandatory<br />
                                <table cols='2' border='0' cellpadding='0' style='width: 100%;'>
                                    <tr>
                                        <td width='50%'><label><font color=#ff0000>*</font>Child Code</label></td>
                                        <td width='50%'><input type='text' size='30' name='childcode' value='' id='childcode'/></td>
                                    </tr>
                                    <tr>
                                        <td width='50%'><label><font color=#ff0000>*</font>First Name</label></td>
                                        <td width='50%'><input type='text' size='30' name='firstname' value='' id='firstname'/></td>
                                    </tr>
                                    <tr>
                                        <td width='50%'><label>Middle Name</label></td>
                                        <td width='50%'><input type='text' size='30' name='middlename' value='' id='middlename'/></td>
                                    </tr>
                                    <tr>
                                        <td width='50%'><label><font color=#ff0000>*</font>Last Name</label></td>
                                        <td width='50%'><input type='text' size='30' name='lastname' value='' id='lastname'/></td>
                                    </tr>
                                    <tr>
                                        <td width='50%'><label>Date Of Birth</label></td>
                                        <td width='50%'><input type='text' size='30' name='dateofbirth' id='dateofbirth' class="datefield" value=''/></td>
                                    </tr>
                                    <tr><td width='50%'><label><font color=#ff0000>*</font>Gender</label></td>
                                        <td width='50%'><select name='gender' id='gender'>
                                                <option value=''/>Select
                                                <option value='Male'>Male</option>
                                                <option value='Female'>Female</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr><td width='50%'><label>Stage of Study</label></td>
                                        <td width='50%'>
                                            <select name='stage' id='stage'>
                                                <option value="0">Select stage</option>
                                                <%
                                                            if (!schoolStages.isEmpty()) {
                                                                for (SchoolStage schoolStage : schoolStages) {
                                                                    out.println("<option value='" + schoolStage.getSchoolStageId() + "'>" + schoolStage.getName() + "</option>");
                                                                }
                                                            }
                                                %>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width='50%'><label>Residence</label></td>
                                        <td width='50%'><input type='text' size='30' name='residence' id='residence' value=''/></td>
                                    </tr>
                                    <tr>
                                        <td width='50%'><label>Address</label></td>
                                        <td width='50%'><input type='text' size='30' name='address' id='address' value=''/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width='50%'><label>District</label></td>
                                        <td width='50%'>
                                            <input type='text' size='30' name='district' id='district' value=''/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width='50%'><label>Health Status</label></td>
                                        <td width='50%'><input type='text' size='30' name='healthstatus' id='healthstatus' value=''/></td>
                                    </tr>
                                    <tr><td width='50%'><label>Parent/Guardian</label></td>
                                        <td width='50%'><input type='text' size='30' name='parentname' id='parentname' value=''/></td></tr>
                                    <tr>
                                        <td width='50%'><label>Relationship</label></td>
                                        <td width='50%'>
                                            <select name='relationship' id='relationship'>
                                                <option value="0">Select Relationship</option>
                                                <%
                                                            if (!relationshipTypes.isEmpty()) {
                                                                for (RelationshipType relationshipType : relationshipTypes) {
                                                                    out.println("<option value='" + relationshipType.getRelationshipTypeId() + "'>" + relationshipType.getName() + "</option>");
                                                                }
                                                            }
                                                %>
                                            </select></td>
                                    </tr>
                                    <tr>
                                        <td width='50%'><label>Next of Kin's Name</label></td>
                                        <td width='50%'><input type='text' size='30' name='nextofkinname' id='nextofkinname' value=''/></td>
                                    </tr>
                                    <tr>
                                        <td width='50%'><label>Relationship</label></td>
                                        <td width='50%'>
                                            <select name='nextofrelationship' id='nextofrelationship'>
                                                <option value="0">Select Relationship</option>
                                                <%
                                                            if (!relationshipTypes.isEmpty()) {
                                                                for (RelationshipType relationshipType : relationshipTypes) {
                                                                    out.println("<option value='" + relationshipType.getRelationshipTypeId() + "'>" + relationshipType.getName() + "</option>");
                                                                }
                                                            }
                                                %>
                                            </select></td>
                                    </tr>
                                    <tr><td width='50%'><label>Next of Kin's Phonenumber</label></td>
                                        <td width='50%'>
                                            <input type='text' size='30' name='phonenumber' id='phonenumber' value=''/></td>
                                    </tr>
                                    <tr>
                                        <td width='50%'><label>Social Worker's Comments</label></td><td width='50%'>
                                            <input type='text' size='30' name='workercomments' id='workercomments' value=''/></td>
                                    </tr>
                                    <tr>
                                        <td colspan='2' width='100%'>
                                            <input type='submit' name='newusersubmit' id='newusersubmit' value='Register Child'/>
                                        </td>
                                    </tr>
                                </table>
                            </form>
                        </div>
                        <!-- end #content -->
                        <div id="sidebar">
                            <div class="navigation">
                                <div class="navhead">Welcome </div>
                                <%
                                            if (loggedInUser != null) {
                                                out.println("<div id='welcomemsg'>Welcome " + loggedInUser.getFirstName() + " " + loggedInUser.getLastName() + "</div>");
                                            }

                                %>
                                <form action="loginlogout" method="post" class="link">
                                    <input type="hidden" value="logout" name="action" />
                                    <input type="submit" value="Log Out"/>
                                </form>

                            </div>

                        </div>
                        <!-- end #sidebar -->
                        <div style="clear: both;">&nbsp;</div>
                    </div>
                </div>
            </div>
            <!-- end #page -->
        </div>
        <div id="footer">
            <p>Copyright (c) 2011 prs.org. All rights reserved. Design by <a href="http://rwebs.javassl.com/">Java Servlet Systems Limited</a>.</p>
        </div>
        <!-- end #footer -->
    </body>
</html>
